package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {


    /**
     * 查询当前分类是否关联了菜品
     * @param id
     * @return
     */
    @Select("select count(id) from dish where category_id = #{id}")
    Integer countByCategoryId(Long id);


    /**
     * 新增菜品
     * @param dish
     *
     */
    @AutoFill(OperationType.INSERT)
    void insertDishWithFlavor(Dish dish);


    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> selectPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 批量删除菜品
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 通过dish的id获取该菜品的状态
     * @param id
     */
    @Select("select * from dish where id = #{id}")
    Dish selectgetStatus(Long id);

    /**
     * 根据id删除菜品
     * @param id
     */
    @Delete("delete from Dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select d.*,c.`name` categoryName from dish d LEFT OUTER JOIN category c on d.category_id = c.id where d.id = #{id}")
    DishVO selectDishById(Long id);

    /**
     * 更新dish表
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateOnlyDish(Dish dish);

    /**
     * 根据分类id查询分类下的菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectDishByCategoryId(Long categoryId);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 根据setmeal——id查询dish获取状态
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    /**
     * 根据dishid查询口味数据
     * @return
     * @param id
     */
    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> selectFlavorByDishId(Long id);
}
